package com.wc.alorithm_luogu.P5143;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/5/13 16:38
 * @description https://www.luogu.com.cn/problem/P5143
 * 攀爬者
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            Point point = new Point();
            point.x = sc.nextInt();
            point.y = sc.nextInt();
            point.z = sc.nextInt();
            points[i] = point;
        }

        // 对Z轴点排序
        Arrays.sort(points, Comparator.comparingInt(o -> o.z));

        double distant = 0;

        for (int i = 1; i < n; i++) {
            distant += twoPointOfDistant(points[i], points[i - 1]);
        }

        System.out.printf("%.3f",distant);
    }

    // 计算两点距离
    static double twoPointOfDistant(Point point1, Point point2) {
        double xx = Math.pow(point1.x - point2.x, 2);
        double yy = Math.pow(point1.y - point2.y, 2);
        double zz = Math.pow(point1.z - point2.z, 2);
        return Math.pow(xx + yy + zz, 0.5);
    }

    // 坐标点
    static class Point {
        int x;
        int y;
        int z;
    }
}
